package com.usian.controller;

import com.github.pagehelper.PageInfo;
import com.usian.admin.AdminUser;
import com.usian.service.AdminUserService;
import com.usian.vo.Result;
import jakarta.websocket.server.PathParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 米西米西
 */
@RestController
@RequestMapping("/api/adminUser")
public class AdminUserController {

    @Autowired
    private AdminUserService adminUserService;

    /**
     * 接口：登录验证
     */
    @PostMapping("/login")
    public Result login(@RequestBody AdminUser adminUser){
        AdminUser adminUser1 = adminUserService.login(adminUser);
//        判断如果是null，则登录失败，否则登录成功
        if (adminUser1 == null){
            return Result.error("登录失败");
        }else {
            return Result.success(adminUser1);
        }
    }

    /**
     * 接口：注册
     */
    @PostMapping("/register")
    public Result register(@RequestBody AdminUser adminUser){
        Integer i = adminUserService.register(adminUser);
        if (i == 0){
            return Result.error("注册失败");
        }else {
           adminUserService.insterCode(adminUser);
           return Result.success();
        }
    }


    @PostMapping("/findPage/{pageSize}/{pageNum}")
    public Result findPage(@PathVariable Integer pageSize, @PathVariable Integer pageNum, @RequestBody AdminUser adminUser){
        PageInfo<AdminUser> page = adminUserService.findPage(pageSize,pageNum,adminUser);
        return Result.success(page);
    }





}
